package com.liyunc.demo.comp.common.exceptions;

import com.liyunc.demo.comp.common.exceptions.enums.ErrorCode;
import lombok.Getter;

/**
 * @author liyuncong
 * @version 1.0
 * @file ApplicationException
 * @brief ApplicationException
 * @details ApplicationException
 * @date 2022-04-28
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-04-28                      liyuncong          Created
 */
public class ApplicationException extends RuntimeException {
    @Getter
    private final int code;

    public ApplicationException(int code, String message) {
        super(message);
        this.code = code;
    }

    public ApplicationException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public ApplicationException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = Math.toIntExact(errorCode.getCode());
    }

    public ApplicationException(ErrorCode errorCode, Throwable cause) {
        super(errorCode.getMessage(), cause);
        this.code = Math.toIntExact(errorCode.getCode());
    }
}
